<template>
    <div>
        
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
 <el-form-item label="请假类型" prop="type">
    <el-select v-model="ruleForm.type" placeholder="事假">
      <el-option label="事假" value="事假"></el-option>
      <el-option label="年假" value="年假"></el-option>
      <el-option label="病假" value="病假"></el-option>
      <el-option label="婚假" value="婚假"></el-option>
      <el-option label="产假" value="产假"></el-option>
      <el-option label="陪产假" value="陪产假"></el-option>
    </el-select>
  </el-form-item>
  <el-form-item label="开始时间" required>
    <el-col :span="11">
      <el-form-item prop="date1">
        <el-date-picker  type="datetime" placeholder="选择日期时间" v-model="ruleForm.date1" style="width: 100%;"></el-date-picker>
      </el-form-item>
    </el-col>
  </el-form-item>
  <el-form-item label="结束时间" required>
    <el-col :span="11">
      <el-form-item prop="date2">
        <el-date-picker  type="datetime" placeholder="选择日期时间" v-model="ruleForm.date2" style="width: 100%;"></el-date-picker>
      </el-form-item>
    </el-col>
  </el-form-item>
  <el-form-item label="提交时间" required>
    <el-col :span="11">
      <el-form-item prop="date3">
        <el-date-picker type="datetime" placeholder="选择日期时间" v-model="ruleForm.date3" style="width: 100%;"></el-date-picker>
      </el-form-item>
    </el-col>
  </el-form-item>
    <el-form-item label="请假原因" prop="name">
    <el-input v-model="ruleForm.name"></el-input>
  </el-form-item>
   <el-form-item>
    <el-button type="primary" @click="submitForm('ruleForm')">立即提交</el-button>
    <el-button @click="resetForm('ruleForm')">重置</el-button>
  </el-form-item>
        </el-form>
  
  </div>
</template>
<script>
import format from '@/plugins/format.js'
  export default {
    data() {
      return {
        ruleForm: {
            date1: '',
            date2: '',
            date3: '',
          name: '',
          region: '',
          delivery: false,
          type: [],
          resource: '',
          desc: ''
        },
         leave: {
            user_name:'李四',
            user_id: '9',
            leave_type: '',
            start_date:'',
            end_date: '',
            add_date:'',
            flow_no:'1001',
            leave_reason:'',
            current_node:'1',
            state:'1',
          },
        rules: {
          name: [
            { required: true, message: '请输入请假内容', trigger: 'blur' },
            { min: 3, max: 100, message: '长度在 3 到 100 个字符', trigger: 'blur' }
          ],
          region: [
            { required: true, message: '请选择开始时间', trigger: 'change' }
          ],
          date1: [
            { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
          ],
          date2: [
            { type: 'date', required: true, message: '请选择时间', trigger: 'change' }
          ],
         
          
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
              this.leave.leave_type=this.ruleForm.type;
              this.leave.start_date= format( this.ruleForm.date1, 'YYYY-MM-DD HH:mm:ss');
              this.leave.end_date=format( this.ruleForm.date2, 'YYYY-MM-DD HH:mm:ss');
              this.leave.add_date=format( this.ruleForm.date3, 'YYYY-MM-DD HH:mm:ss');
              this.leave.leave_reason=this.ruleForm.name
               alert(this.leave.start_date);
               console.log(this.leave.start_date);
           this.$http.post("/aa", this.leave).then(res=>{
               if(res.data.code<0){
                     this.$message(res.data.msg);
                    }else{
                      this.$message(res.data.msg);
                     this.$router.push("/home/myApply/apply")
                    }
           })
          } else {
            this.$message("提交失败");
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>